home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / GL / libdemo / timer.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  93 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #ifndef _timer_
  18. #define _timer_
  19.  
  20. #include <sys/time.h>
  21.  
  22. /*
  23.  * A usefull timer class.  Start and stop are self explanetory.
  24.  * Elapse will return seconds since last start if the timer is running or
  25.  * seconds between last start and stop if the timer is not running.
  26.  */
  27.  
  28. #ifdef __cplusplus
  29.  
  30. class timer
  31. {
  32. public:
  33.     timer();
  34.     void  start();
  35.     virtual void  stop();
  36.     float elapse();
  37.     float elapseStart();    // atomic version of elapse(); start();
  38. private:
  39.     struct timeval beginTime, endTime;
  40.     int running;
  41. };
  42.  
  43. class totalTimer : public timer
  44. {
  45. public:
  46.     totalTimer(char *);
  47.     float getTotal();
  48.     int getCount();
  49.     virtual void stop();
  50.  
  51.     char * description;
  52. private:
  53.     int count;
  54.     float totalTime;
  55. };
  56.  
  57. class perfTimer : public totalTimer
  58. {
  59. public:
  60.     perfTimer(char * d) : totalTimer(d) {}
  61.     ~perfTimer();
  62.     void print();
  63. };
  64.  
  65. /*
  66.  * Useful demo routines for showing the current frame/polygon/... rate.
  67.  * Simply call showFrameRate just before swapbuffers to get the frame rate.
  68.  * Disable the rate display with setFrameRateActive(FALSE).  To show something
  69.  * other than frame rate (eg. polygon rate) call setFrameRateMultiplier(foo)
  70.  * before showFrameRate.  Foo is the quantity of whatevery is to be measured.
  71.  * Call setFrameRateDescription("%5.2f Whoopies/sec") to change the description
  72.  * of the rate display.  The string given is used in an sprintf call with one
  73.  * float argument given.  As the measured rate changes, the rate displayed
  74.  * will approach and become this rate in about one second.  To change this
  75.  * time call setFrameRateConvergence(t), where t is time in seconds. 
  76.  */
  77.  
  78.  
  79. extern "C" {
  80.  
  81. #endif 
  82.  
  83. void showFrameRate();
  84. void setFrameRateMultiplier(float);
  85. void setFrameRateDescription(char *);
  86. void setFrameRateActive(int);
  87. void setFrameRateConvergence(float);
  88.     
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif
  93.